package com.wp.land.api;

import com.wp.land.context.VDataContext;
import com.wp.land.entity.citys.CityData;
import com.wp.land.entity.soilenv.EnvData;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @author: zhou
 * @Description:
 * @Date:Create in 2019/05/09
 * @Modified By:
 */

@RestController
@RequestMapping("/api/")
public class LandEnv {

    /**
     * 获取显示值
     * @param index
     * @return
     */
    @RequestMapping(value = "/env/{index}/{part}", method = RequestMethod.GET)
    public Object getQrData(@PathVariable String index,@PathVariable String part){

        Objects.requireNonNull(index,"index 不能为空");
        Objects.requireNonNull(index,"part 不能为空");

        List listReturn = new ArrayList(16);
        EnvData envData = VDataContext.list_envData.get(VDataContext.envIndex);
        Map params = new HashMap(16);

        if (part.equals("11")){
            List listData =  envData.getListHhw_1();
            return listData;
        } else if (part.equals("12")){
            List listData =  envData.getListHhw_2();
            return listData;
        } else if (part.equals("13")){
            List listData =  envData.getListHhw_3();
            return listData;
        } else if (part.equals("14")){
            List listData =  envData.getListHhw_4();
            return listData;
        } else if (part.equals("15")){
            List listData =  envData.getListHhw_5();
            return listData;
        }

        else if (part.equals("21")){
            List listData =  envData.getListYs_1();
            return listData;
        }else if (part.equals("22")){
            List listData =  envData.getListHhw_2();
            return listData;
        }else if (part.equals("23")){
            List listData =  envData.getListHhw_3();
            return listData;
        }else if (part.equals("24")){
            List listData =  envData.getListHhw_4();
            return listData;
        }else if (part.equals("25")){
            List listData =  envData.getListHhw_5();
            return listData;
        } else if (part.equals("0")){
            params.put("value",envData.getName());
        } else if(part.equals("00")){
            List listData =  envData.getEnvList();
            return listData;
        }

        listReturn.add(params);

        return listReturn;
    }


    @RequestMapping(value = "/switchCity/{index}", method = RequestMethod.GET)
    public Object switchCitys(@PathVariable String index){


        List listReturn = new ArrayList(16);
        CityData cityData = VDataContext.citysList.get(VDataContext.cityIndex);
        Map params = new HashMap(16);

        if (index.equals("1")){
            return cityData.getCityJSON();
        } else if (index.equals("2")){
            params.put("name","");
            params.put("value",cityData.getCityName());
            listReturn.add(params);

        } else if (index.equals("3")){
            params.put("value",cityData.getArea());
            listReturn.add(params);
        } else if (index.equals("4")){
            listReturn.add(cityData.getCityLL());
            return listReturn;
        }

        return listReturn;

    }


}
